package com.schoolMall.controller.fronted;

import com.schoolMall.domain.HeadLine;
import com.schoolMall.domain.ShopCategory;
import com.schoolMall.service.HeadLineService;
import com.schoolMall.service.ShopCategoryService;
import com.schoolMall.utils.ModelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author:zyh
 * @Time:2021-09-03-12:24
 * @email:1269231889@qq.com
 */
@Controller
@RequestMapping("/schoolMall/mainPage")
public class MainPageController {
    @Autowired
    private ShopCategoryService shopCategoryService;
    @Autowired
    private HeadLineService headLineService;


    @ResponseBody
    @GetMapping("/pageInfo")
    public Map<String, Object> getPageInfo() {
        Map<String, Object> model = new HashMap<>();
        try {
            List<ShopCategory> shopCategoryList = shopCategoryService.queryShopCategoryList(null);
            model.put("shopCategoryList", shopCategoryList);
        } catch (Exception e) {
            return ModelUtil.fail("查询商品类别失败");
        }

        try {
            HeadLine headLine = new HeadLine();
            headLine.setEnableStatus(1);
            List<HeadLine> headLines = headLineService.queryHeadLineByCondition(headLine);
            model.put("headLines",headLines);
        } catch (Exception e) {
            return ModelUtil.fail("头条查询失败");
        }
        model.put("success", true);
        return model;
    }
}
